package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户提交订单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "用户下单")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {

        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);

        return Result.success(orderSubmitVO);
    }

    /**
     * 用户支付 并且商家端来单提醒
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation(value = "用户支付")
    public Result<OrderPaymentVO> userPayOrder(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        // 支付成功 修改订单状态
        orderService.paymentOrder(ordersPaymentDTO);

        OrderPaymentVO orderPaymentVO = new OrderPaymentVO();
        return Result.success(orderPaymentVO);
    }

    /**
     * 查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/historyOrders")
    @ApiOperation(value = "查询用户历史订单")
    public Result<PageResult> pageListOrder(OrdersPageQueryDTO ordersPageQueryDTO) {

        PageResult pageResult = orderService.pageListOrder(ordersPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 用户查看订单详情
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation(value = "用户查看订单详情")
    public Result<OrderVO> getOrderDetail(@PathVariable Long id) {

        OrderVO orderVO = orderService.getOrderDetail(id);

        return Result.success(orderVO);
    }

    /**
     * 再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation(value = "用户再来一单")
    public Result<String> againOrder(@PathVariable Long id) {

        orderService.againOrder(id);

        return Result.success("再来一单成功");
    }

    /**
     * 用户取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation(value = "用户取消订单")
    public Result<String> cancelOrder(@PathVariable Long id) {

        orderService.cancelOrder(id);
        return Result.success("用户取消订单");
    }


    /**
     * 用户催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation(value = "用户催单")
    public Result<String> reminder(@PathVariable Long id) {
        orderService.reminder(id);
        return Result.success("用户催单成功");
    }

}
